package com.adgox.tiantianbiting.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.adgox.tiantianbiting.R;
import com.adgox.tiantianbiting.bean.TradeRecordBean;

import org.w3c.dom.Text;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by tang on 2019/1/4.
 */

public class TradeRecordAdapter extends RecyclerView.Adapter<TradeRecordAdapter.ViewHolder> {
    private List<TradeRecordBean> datas;

    public TradeRecordAdapter(List<TradeRecordBean> datas) {
        this.datas = datas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_trade_record, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        TradeRecordBean bean = datas.get(position);
        if (bean.getPayStatus() == 0){
            setAllGone(holder);
            holder.tvType.setText("充值");
            holder.tvDate.setText(bean.getCreateTimeStr());
            holder.tvTitleRechargeNum.setVisibility(View.VISIBLE);
            holder.tvRechargeNum.setVisibility(View.VISIBLE);
            holder.tvRechargeNum.setText(bean.getBalance()+"听币");
        } else if (bean.getPayStatus() == 1){
            setAllGone(holder);
            holder.tvType.setText("购买");
            holder.tvDate.setText(bean.getCreateTimeStr());
            holder.tvTitleName.setVisibility(View.VISIBLE);
            holder.tvName.setVisibility(View.VISIBLE);
            holder.tvName.setText(bean.getTitle());
            holder.tvTitlePrice.setVisibility(View.VISIBLE);
            holder.tvPrice.setVisibility(View.VISIBLE);
            holder.tvPrice.setText(bean.getEveryPrice()+"听币");
            holder.tvTitleNum.setVisibility(View.VISIBLE);
            holder.tvNum.setVisibility(View.VISIBLE);
            holder.tvNum.setText(bean.getAmount()+"件");
            holder.tvTitleTotal.setVisibility(View.VISIBLE);
            holder.tvTotal.setVisibility(View.VISIBLE);
            holder.tvTotal.setText(bean.getBalance()+"听币");
        } else if (bean.getPayStatus() == 2){
            setAllGone(holder);
            holder.tvType.setText("提现");
            holder.tvDate.setText(bean.getCreateTimeStr());
            holder.tvTitleWithdrNum.setVisibility(View.VISIBLE);
            holder.tvWithdrawNum.setVisibility(View.VISIBLE);
            holder.tvWithdrawNum.setText(bean.getBalance()+"听币");
//            holder.tvTitleWithdrawType.setVisibility(View.VISIBLE);
//            holder.tvWithdrawType.setVisibility(View.VISIBLE);
//            holder.tvWithdrawType.setText(bean.getTitle());
        } else if (bean.getPayStatus() == 3){
            setAllGone(holder);
            holder.tvType.setText("签到有礼");
            holder.tvDate.setText(bean.getCreateTimeStr());
            holder.tvTitleBonusName.setVisibility(View.VISIBLE);
            holder.tvBonusName.setText("签到奖励");
            holder.tvBonusName.setVisibility(View.VISIBLE);
            holder.tvTitleBonusNum.setVisibility(View.VISIBLE);
            holder.tvBonusNum.setText(bean.getBalance()+"听币");
            holder.tvBonusNum.setVisibility(View.VISIBLE);
        } else if (bean.getPayStatus() == 10 || bean.getPayStatus() == 11){
            setAllGone(holder);
            holder.tvType.setText("关注有礼");
            holder.tvDate.setText(bean.getCreateTimeStr());
            holder.tvTitleBonusName.setVisibility(View.VISIBLE);
            holder.tvBonusName.setText("关注奖励");
            holder.tvBonusName.setVisibility(View.VISIBLE);
            holder.tvTitleBonusNum.setVisibility(View.VISIBLE);
            holder.tvBonusNum.setText(bean.getBalance()+"听币");
            holder.tvBonusNum.setVisibility(View.VISIBLE);
        } else if (bean.getPayStatus() == 12){
            setAllGone(holder);
            holder.tvType.setText("小姐姐送福利");
            holder.tvDate.setText(bean.getCreateTimeStr());
            holder.tvTitleBonusName.setVisibility(View.VISIBLE);
            holder.tvBonusName.setText("小姐姐送听币");
            holder.tvBonusName.setVisibility(View.VISIBLE);
            holder.tvTitleBonusNum.setVisibility(View.VISIBLE);
            holder.tvBonusNum.setText(bean.getBalance()+"听币");
            holder.tvBonusNum.setVisibility(View.VISIBLE);
        }
    }

    private void setAllGone(ViewHolder holder) {
        holder.tvTitleName.setVisibility(View.GONE);
        holder.tvName.setVisibility(View.GONE);
        holder.tvTitlePrice.setVisibility(View.GONE);
        holder.tvPrice.setVisibility(View.GONE);
        holder.tvTitleNum.setVisibility(View.GONE);
        holder.tvNum.setVisibility(View.GONE);
        holder.tvTitleTotal.setVisibility(View.GONE);
        holder.tvTotal.setVisibility(View.GONE);
        holder.tvTitleRechargeNum.setVisibility(View.GONE);
        holder.tvRechargeNum.setVisibility(View.GONE);
        holder.tvTitleWithdrawType.setVisibility(View.GONE);
        holder.tvWithdrawType.setVisibility(View.GONE);
        holder.tvTitleWithdrNum.setVisibility(View.GONE);
        holder.tvWithdrawNum.setVisibility(View.GONE);
        holder.tvTitleBonusName.setVisibility(View.GONE);
        holder.tvBonusName.setVisibility(View.GONE);
        holder.tvTitleBonusNum.setVisibility(View.GONE);
        holder.tvBonusNum.setVisibility(View.GONE);
    }

    public void addDatas(List<TradeRecordBean> list){
        datas.addAll(list);
    }



    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_type)
        TextView tvType;
        @BindView(R.id.tv_title_name)
        TextView tvTitleName;
        @BindView(R.id.tv_title_price)
        TextView tvTitlePrice;
        @BindView(R.id.tv_title_num)
        TextView tvTitleNum;
        @BindView(R.id.tv_title_total)
        TextView tvTitleTotal;
        @BindView(R.id.tv_title_recharge_num)
        TextView tvTitleRechargeNum;
        @BindView(R.id.tv_title_withdraw_type)
        TextView tvTitleWithdrawType;
        @BindView(R.id.tv_title_withdr_num)
        TextView tvTitleWithdrNum;
        @BindView(R.id.tv_title_bonus_name)
        TextView tvTitleBonusName;
        @BindView(R.id.tv_title_bonus_num)
        TextView tvTitleBonusNum;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_num)
        TextView tvNum;
        @BindView(R.id.tv_total)
        TextView tvTotal;
        @BindView(R.id.tv_recharge_num)
        TextView tvRechargeNum;
        @BindView(R.id.tv_withdraw_type)
        TextView tvWithdrawType;
        @BindView(R.id.tv_withdraw_num)
        TextView tvWithdrawNum;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.tv_bonus_name)
        TextView tvBonusName;
        @BindView(R.id.tv_bonus_num)
        TextView tvBonusNum;
        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
